﻿var CheckPwd = {
    O_color: "#eeeeee", L_color: "#FF0000", M_color: "#FF9900", H_color: "#33CC00",
    _CharMode: function (iN) {
        if (iN >= 48 && iN <= 57) return 1;
        else if (iN >= 65 && iN <= 90) return 2;
        else if (iN >= 97 && iN <= 122) return 4;
        return 8;
    },
    _bitTotal: function (num) {
        modes = 0;
        for (i = 0; i < 4; i++) {
            if (num & 1) modes++;
            num >>>= 1;
        }
        return modes;
    },
    _checkStrong: function (sPW) {
        if (sPW.length <= 4)
            return 0;
        Modes = 0;
        for (i = 0; i < sPW.length; i++) {
            Modes |= this._CharMode(sPW.charCodeAt(i));
        }
        return this._bitTotal(Modes);
    },
    pwStrength: function (pwd) {
        if (pwd == null || pwd == '') {
            Lcolor = Mcolor = Hcolor = this.O_color;
        }
        else {
            S_level = this._checkStrong(pwd);
            switch (S_level) {
                case 0:
                    Lcolor = Mcolor = Hcolor = this.O_color;
                case 1:
                    Lcolor = this.L_color;
                    Mcolor = Hcolor = this.O_color;
                    break;
                case 2:
                    Lcolor = Mcolor = this.M_color;
                    Hcolor = this.O_color;
                    break;
                default:
                    Lcolor = Mcolor = Hcolor = this.H_color;
            }
            if ($("#cphMain_cphMain_hfPwdLevel") != null) {
                $("#cphMain_cphMain_hfPwdLevel").attr("value", S_level);
            }
            if ($("#cphMain_cphMain_hfPwdLevel") != null) {
                $("#cphMain_cphMain_hfPwdLevel").attr("value", S_level);
            }
        }
        $("#strength_L").css("background", Lcolor);
        $("#strength_M").css("background", Mcolor);
        $("#strength_H").css("background", Hcolor);
        return;
    }
};
 